<template>
  <div class="app-container">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input size="small" v-model="queryItems[0].value" :placeholder="$t('mobile')" clearable/>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="queryItems[1].value" :placeholder="$t('name')" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" @click="getDataList()">{{ $t('query') }}</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button v-if="$hasPermission('sys:user:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button size="mini" v-hasPermi="['sys:applyAccount:delete']" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button v-if="$hasPermission('sys:user:export')" type="info" @click="exportHandle()">{{ $t('export') }}</el-button>-->
<!--      </el-form-item>-->
    </el-form>
    <el-table
      v-loading="dataListLoading"
      :data="dataList"
      size="mini"
      border
      stripe
      @sort-change="dataListSortChangeHandle"
      style="width: 100%;">
<!--      <el-table-column type="selection" header-align="center" align="center" width="50"/>-->
      <el-table-column prop="name" :label="$t('name')" header-align="center" align="center"/>
      <el-table-column prop="phone" :label="$t('mobile')" header-align="center" align="center"/>
      <el-table-column prop="companyName" :label="$t('companyName')" header-align="center" align="center"/>
      <el-table-column prop="referrerPhone" :label="$t('referrerPhone')" header-align="center" align="center"/>
      <el-table-column prop="status" :label="$t('applyManager.status')" sortable="custom" header-align="center" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" size="mini" type="danger">{{ $t('applyManager.status0') }}</el-tag>
          <el-tag v-else-if="scope.row.status === 1" size="mini" type="">{{ $t('applyManager.status1') }}</el-tag>
          <el-tag v-else-if="scope.row.status === 2" size="mini" type="success">{{ $t('applyManager.status2') }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" :label="$t('applyManager.createTime')" sortable="custom" header-align="center" align="center" width="180"/>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template slot-scope="scope">
          <el-popover
                  placement="top"
                  width="120">
            <p>审核申请状态？</p>
            <div style="text-align: right; margin: 0">
              <el-button type="danger" size="mini" @click="changeStatus(scope.row,0)">拒绝</el-button>
              <el-button type="primary" size="mini" @click="changeStatus(scope.row,2)">通过</el-button>
            </div>
            <el-button slot="reference" v-hasPermi="['sys:applyAccount:update']" type="text" size="mini" >审核</el-button>
          </el-popover>
<!--          <el-button v-if="$hasPermission('sys:user:update')" type="text" size="mini" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>-->
<!--          <el-button v-if="$hasPermission('sys:role:delete')"  type="text" size="mini" @click="enableHandle(scope.row)">{{ scope.row.status === 0?$t('status1'):$t('status0')}}</el-button>-->
<!--          <el-button v-if="$hasPermission('sys:user:delete')" type="text" size="mini" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"/>
    <!-- 分页 -->
    <el-pagination
      slot="footer"
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="pageSizeChangeHandle"
      @current-change="pageCurrentChangeHandle">
    </el-pagination>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './applyManagers-add-or-update'
export default {
  mixins: [ mixinViewModule ],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/manager/apply/page',
        getDataListIsPage: true,
        deleteURL: '/manager/apply/delete',
        deleteIsBatch: true,
        exportURL: '/sys/user/export',
        enableURL: '/manager/apply/enable'
      },
      queryItems: [
        {
          field: 'phone',
          as: 'LIKE',
          value: ''
        },
        {
          field: 'name',
          as: 'LIKE',
          value: ''
        }
      ],
      order: 'DESC',
      orderField: 'createTime'
    }
  },
  components: {
    AddOrUpdate
  },
  methods:{
    //改变状态
    changeStatus(row,status){
      this.visible = false;
      let dataItem = Object.assign({}, row) //拷贝数据对象
      dataItem.status = status;
      let params =  {
        id:dataItem.id,
        type: dataItem.type,
        status:dataItem.status
      };
      this.$http.post(this.mixinViewModuleOptions.enableURL, params).then(res => {
        this.$message({
          message: this.$t('prompt.success'),
          type: 'success',
          duration: 500,
          onClose: () => {
            this.visible = false
            this.getDataList()
          }
        })
      }).catch(() => {})
    },
  }

}
</script>
